//
//  SEInquiryAPI.swift
//  SmartEyeForDoctor
//
//  Created by QDSG on 2021/4/20.
//

import Moya

enum SEInquiryAPI {
    /// 获取问诊列表 (type: 1 - 当前接诊 2 - 历史接诊)
    case inquiryList(type: Int, page: Int)
    case inquiryDetail(id: String)
    /// 修改问诊状态
    /// 0-待支付，1支付成功后台发起，2医生同意，3患者收到医生同意，4医生结束发起，5患者同意,6医生拒绝,7患者拒绝结束,8患者未支付取消
    case changeInquiryStatus(id: String, status: String)
    case abortPrescriptionCount
    case doctorCountsDto
}

extension SEInquiryAPI: TargetType {
    var baseURL: URL {
        return URL(string: SEApiManager.baseUrl)!
    }
    
    var path: String {
        switch self {
        case .inquiryList: return "/smarteye/smarteye-inquiry/consultation/queryConsultationDtoList"
        case .inquiryDetail: return "/smarteye/smarteye-inquiry/consultation/getConsultationDtoById"
        case .changeInquiryStatus: return "/smarteye/smarteye-inquiry/consultation/updateConsultationStatus"
        case .abortPrescriptionCount: return "/smarteye/smarteye-inquiry/prescription/queryAbortPrescription"
        case .doctorCountsDto: return "/smarteye/smarteye-inquiry/unine/getDoctorCountsDto"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .inquiryList,
             .changeInquiryStatus:
            return .post
        case .inquiryDetail,
             .abortPrescriptionCount,
             .doctorCountsDto:
            return .get
        }
    }
    
    var sampleData: Data { return "".data(using: .utf8)! }
    
    var task: Task {
        SELog("\(path): \(parameters)")
        switch self {
        case .inquiryList,
             .changeInquiryStatus:
            return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
        case .inquiryDetail,
             .abortPrescriptionCount,
             .doctorCountsDto:
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        }
    }
    
    var headers: [String : String]? {
        return SEApiManager.headers
    }
    
    private var parameters: [String: Any] {
        switch self {
        case let .inquiryList(type, page):
            /// source - 3 医生app，type - 1(当前接诊) 2(历史接诊)，
            return ["source": 3, "type": type, "pageNum": page, "pageSize": 10]
        case let .inquiryDetail(id):
            return ["id": id]
        case let .changeInquiryStatus(id, status):
            return ["id": id, "dealStatus": status]
        case .abortPrescriptionCount, .doctorCountsDto:
            return [:]
        }
    }
}
